﻿using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Fabrication.ValueProviders
{
    internal abstract class CompositeStringProvider : ValueProviderBase<string>
    {
        private readonly IEnumerable<string>[] stringLists;

        protected CompositeStringProvider(params IEnumerable<string>[] stringLists)
        {
            this.stringLists = stringLists;
        }

        protected sealed override string GetValue(object item)
        {
            var sb = new StringBuilder();
            foreach (var stringList in stringLists)
            {
                var index = RandomNumberGenerator.GetInteger(0, stringList.Count() - 1);
                sb.Append(stringList.ElementAt(index)).Append(" ");
            }
            return sb.ToString().TrimEnd();
        }
    }
}